package com.leetcodehot.problems;

public class problems234 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode ReverseList(ListNode head) {
        ListNode dummy = new ListNode(0);
        while (head != null) {
            ListNode node = new ListNode(head.val);
            node.next = dummy.next;
            dummy.next = node;
            head = head.next;
        }
        return dummy.next;
    }

    public boolean isPalindrome(ListNode head) {
        ListNode reverse = ReverseList(head);
        while (reverse != null) {
            if (reverse.val != head.val) return false;
            reverse = reverse.next;
            head = head.next;
        }
        return true;
    }
}
